<%@ page language="java" isELIgnored="false"%>
<%@include file="../common/taglib.jsp"%>

<div id="Conteudo">
	<html:form action="contato">
		<html:hidden property="codigo"></html:hidden>
		<html:hidden property="method"></html:hidden>
		<html:hidden property="state"></html:hidden>
		<h1><bean:message key="contato.label.title"/>:<span><bean:message key="subtitulo.label.cadastro"/></span> </h1>
		<div class="campo">
			<label>
				<bean:message key="contato.label.nome"/><span>*</span>
			</label> 
			<html:text property="nome" style="width:500px;" maxlength="100"></html:text>
		</div>
		<div class="campo">
			<label>
				<bean:message key="contato.label.telefone"/><span>*</span>
			</label>
			<html:text property="telefone" style="width:500px;" maxlength="100"></html:text>
		</div>		
		<div class="campo">
			<label>
				<bean:message key="contato.label.obs"/><span>*</span>
			</label>
			<html:textarea property="obs" style="width:500px;"></html:textarea>
		</div>		
		<br clear="all"/>
		<div class="campo">
			<label><bean:message key="contato.label.empresa"/><span>*</span></label>			
			<html:select property="empresa.codigo" disabled="false">
				<trex:options source="br.com.ia.business.EmpresaBusiness.retrieveAll()" property="codigo" labelProperty="nome"/>
			</html:select>
		</div>								
		<div class="campo">
				<label><bean:message key="contato.label.nova.empresa"/><span>*</span></label>					
				<input type="checkbox" onclick="habilitaNovaEmpresa()"/> 
		</div>					
		<div class="campo">
				<label><bean:message key="empresa.label.nome"/><span>*</span></label>					
				<html:text property="property(empresa.nome)" style="width:500px;" maxlength="100" disabled="true"></html:text>
		</div>					
		
	</html:form>
	
	<%-- <facility-tags:error/>	--%>
	
</div>
<script>
	
	function cancelar(){
		
		document.ContatoForm.method.value = 'prepareSearch';
		document.ContatoForm.submit();		
	}
	
	function salvar(){
		
		var estado = document.ContatoForm.state.value;
		
		if (estado == 'insert'){
			document.ContatoForm.method.value = 'insert';
		}
		else if (estado == 'update'){
			document.ContatoForm.method.value = 'update';
		}
				
		document.ContatoForm.submit();		
	}

	function habilitaNovaEmpresa(){
	
		if(document.ContatoForm.elements['property(empresa.nome)'].disabled  && !document.ContatoForm.elements['empresa.codigo'].disabled){
			document.ContatoForm.elements['property(empresa.nome)'].disabled = false;
			document.ContatoForm.elements['empresa.codigo'].disabled = true;
		}else{
			document.ContatoForm.elements['property(empresa.nome)'].disabled = true;
			document.ContatoForm.elements['empresa.codigo'].disabled = false;
		}
		   
		     
	}
	
</script>